<template>
  <el-form :inline="true" :model="formInline" class="form-inline">
    <el-row class="row">
      <el-form-item label="所属管廊：">
        <el-select
          v-model="formInline.pipeId"
          class="m-2"
          placeholder="--请选择--"
        >
          <el-option
            v-for="item in pipeArray"
            :key="item.id"
            :label="item.pipeName"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="上报时间：">
        <el-date-picker
          v-model="time"
          type="datetimerange"
          format="YYYY-MM-DD HH:mm:ss"
          value-format="YYYY-MM-DD HH:mm:ss"
          range-separator="到"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          @change="change"
          size="small"
        />
      </el-form-item>
      <el-form-item class="btns">
        <el-button type="primary" @click="onSubmit">查询</el-button>
        <el-button type="success" @click="onClear">清空</el-button>
      </el-form-item>
    </el-row>
  </el-form>
</template>

<script setup>
import { reactive, defineEmits, ref } from 'vue'
import { pipelist } from '@/api/back'

const options = reactive({})
const value = ref('')

const formInline = reactive({
  pipeId: '',
  startTime: '',
  endTime: ''
})
const time = ref()
const pipeArray = ref([])
const getListData = async () => {
  pipeArray.value = await pipelist()
}
getListData()

const change = (res) => {
  if (res) {
    formInline.startTime = res[0]
    formInline.endTime = res[1]
  } else {
    formInline.startTime = ''
    formInline.endTime = ''
  }
}

const emits = defineEmits(['onSearch'])

const onSubmit = () => {
  console.log('formInline', formInline)
  emits('onSearch', formInline)
}
const onClear = () => {
  formInline.pipeId = ''
  formInline.startTime = ''
  formInline.endTime = ''
  time.value = ''
  emits('onSearch', formInline)
}
</script>

<style lang="scss" scoped>
.form-inline {
  width: 100%;
  position: relative;
  // display: flex;
  // column-gap: 20px;
  // padding-bottom: 33px;
  .row {
    display: flex;
    column-gap: 5%;
  }
  .btns {
    position: absolute;
    right: 0;
    top: 1px;
    .m-left {
      margin-left: 20px;
    }
  }
}
</style>
